package com.future.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2Config {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                // 指定"暴露给Swagger去展示"的接口所在的包
                .apis(RequestHandlerSelectors.basePackage("com.future.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    // 创建API（Web数据接口）的基本信息，这些信息会展现在文档页面中
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                // 标题
                .title("Observer Restful API文档")
                // 描述
                .description("后端API接口文档")
                // 作者信息
                .contact(new Contact("陈孝燈", "https://github.com/chenxiaodeng", "2516904006@qq.com"))
                // 版本号
                .version("1.0")
                .build();
    }
}
